package Test.redis;

import Test.Test02.Student;
import Test.Test02.Teacher;
import cn.hutool.core.lang.UUID;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;

/**
 * @Author kirito
 * @Date 2023/12/28 16:38
 * @PackageName:Test.redis
 * @ClassName: PipeLine
 * @Description:
 * mset在redis底层是一个原子性操作，不会被其他命令打断，所以会比pipeLine快一些
 * Pipeline 是命令语句拼接，可能会被其他命令打断
 * @Version 1.0
 */
public class PipeLineTest {
    public static void main(String[] args) {
        Jedis jedis = new Jedis();
        // 创建管道
        Pipeline pipeline = jedis.pipelined();
        long b = System.currentTimeMillis();
        for (int i = 1; i <= 100000; i++) {
            // 放入命令到管道
            pipeline.set("test:key_" + i, "value_" + i);
            if (i % 1000 == 0) {
                // 每放入1000条命令，批量执行
                pipeline.sync();
            }
        }
        long e = System.currentTimeMillis();
        System.out.println("time: " + (e - b));


/*        String[] arr = new String[2000];
        int j;
        long b = System.currentTimeMillis();
        for (int i = 1; i <= 100000; i++) {
            j = (i % 1000) << 1;
            arr[j] = "test:key_" + i;
            arr[j + 1] = "value_" + i;
            if (j == 0) {
                jedis.mset(arr);
            }
        }
        long e = System.currentTimeMillis();
        System.out.println("time: " + (e - b));*/
//        Object s = new Student();
//        System.out.println(s instanceof Teacher);
    }
}
